home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1812 / 1812.xpi / chrome / colt.jar / content / custom_format.js < prev    next >
Text File  |  2009-08-13  |  4KB  |  110 lines

  1. var objCoLTCustomFormat = {
  2.     CustomFormatBuffer : null,
  3.     
  4.     ClearCustomFormat: function()
  5.     {
  6.         window.opener.objCoLTOptions.CustomFormatLabel = null;
  7.         window.opener.objCoLTOptions.CustomFormatFormat = null;
  8.         window.opener.objCoLTOptions.CustomFormatRichText = null;
  9.     },
  10.  
  11.     InitCustomFormat: function()
  12.     {
  13.         var stringBundle = document.getElementById("CLT-String-Bundle");
  14.     
  15.         if(window.arguments[0] == "add")
  16.             document.title = stringBundle.getString("CLT_AddCustomFormat");
  17.         else
  18.         {
  19.             document.title = stringBundle.getString("CLT_EditCustomFormat");
  20.     
  21.             document.getElementById("CLT-Custom-Format-Label").value = window.arguments[1];
  22.             document.getElementById("CLT-Custom-Format-Format").value = window.arguments[2];
  23.     
  24.             if(window.arguments[2] == objCoLTOptions.RichTextFormatLabel)
  25.                 document.getElementById("CLT-Custom-Format-RichText").checked = true;
  26.         }
  27.     
  28.         this.UpdateCustomFormatControls();
  29.     },
  30.     
  31.     OnCustomFormatLink: function()
  32.     {
  33.         var url = "http://www.borngeek.com/firefox/colt/custom-formats/";
  34.         
  35.         var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
  36.         var currentWindow = windowMediator.getMostRecentWindow("navigator:browser");
  37.         if (currentWindow)
  38.         {
  39.             try
  40.             {
  41.                 currentWindow.delayedOpenTab(url);
  42.             }
  43.             catch(e)
  44.             {
  45.                 currentWindow.loadURI(url);
  46.             }
  47.         }
  48.         else
  49.         {
  50.             var protocolService = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
  51.                                                                             .getService(Components.interfaces.nsIExternalProtocolService);
  52.             var uri = Components.classes["@mozilla.org/network/io-service;1"]
  53.                                                     .getService(Components.interfaces.nsIIOService)
  54.                                                     .newURI(url, null, null);
  55.             protocolService.loadURI(uri, null);
  56.         }
  57.     },
  58.  
  59.     SaveCustomFormat: function()
  60.     {
  61.         var stringBundle = document.getElementById("CLT-String-Bundle");
  62.         
  63.         var label = objCoLTOptions.Trim(document.getElementById("CLT-Custom-Format-Label").value);
  64.         var format = objCoLTOptions.Trim(document.getElementById("CLT-Custom-Format-Format").value);
  65.         var richText = document.getElementById("CLT-Custom-Format-RichText").checked;
  66.         var errors = "";
  67.     
  68.         if(!label)
  69.             errors += stringBundle.getString("CLT_EmptyLabel") + "\n";
  70.     
  71.         if(!richText && !format)
  72.             errors += stringBundle.getString("CLT_EmptyFormat") + "\n";
  73.     
  74.         if(errors)
  75.         {
  76.             Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService).alert(null, stringBundle.getString("CLT_ErrorMessage"), errors);
  77.             return false;
  78.         }
  79.         else
  80.         {
  81.             window.opener.objCoLTOptions.CustomFormatLabel = label;
  82.             window.opener.objCoLTOptions.CustomFormatFormat = format;
  83.             window.opener.objCoLTOptions.CustomFormatRichText = richText;
  84.             return true;
  85.         }
  86.     },
  87.  
  88.     UpdateCustomFormatControls: function()
  89.     {
  90.         if(this.CustomFormatBuffer == null)
  91.             this.CustomFormatBuffer = document.getElementById("CLT-Custom-Format-Format").value;
  92.     
  93.         if(document.getElementById("CLT-Custom-Format-RichText").checked)
  94.         {
  95.             document.getElementById("CLT-Custom-Format-Format").disabled = true;
  96.             document.getElementById("CLT-Custom-Format-Format").value = objCoLTOptions.RichTextFormatLabel;
  97.         }
  98.         else
  99.         {
  100.             document.getElementById("CLT-Custom-Format-Format").disabled = false;
  101.     
  102.             if(this.CustomFormatBuffer == objCoLTOptions.RichTextFormatLabel)
  103.                 document.getElementById("CLT-Custom-Format-Format").value = "";
  104.             else
  105.                 document.getElementById("CLT-Custom-Format-Format").value = this.CustomFormatBuffer;
  106.         }
  107.     }
  108. };
  109.  
  110.